package net.sureon.common.mail;


import java.util.Locale;
import java.util.Map;

import net.sureon.common.exception.SureonException;

/**
 * Interface to create the mail content, this interface is used by the MailProcessor
 * to create the content asynchronously, for every recipient in the method createMail
 * is called.
 */
public interface MailCreator {

    /**
     * This method is call ONLY ONCE by the MailProcessor.
     * This method should be used to initialize things in
     * this class.
     *
     * @param key          The Key that identifies the task
     * @param templateName The Template Name
     * @param mailData The replacement Map
     * @param locale       The Locale of the email
     * @throws SureonException
     */
    void preProcessMail(Object key,
        String templateName, MailData mailData, Locale locale) throws SureonException;

    /**
     * Creates the mail from the template. This method is
     * called once for every email address. The generated
     * String object should have the content of the mail,
     * all the other mail attributes it taken care off by
     * the MailProcessor
     *
     * @param key    The Key that identifies the task
     * @param to     The email address of the recipient
     * @param mailData The MailData object
     * @return The content of the mail
     * @throws SureonException
     */
    String createMail(Object key, String to, MailData mailData) throws SureonException;

    /**
     * This method is call ONLY ONCE by the MailProcessor.
     * This method should be used for clean up in this class
     *
     * @param key    The Key that identifies the task
     */
    void postProcessMail(Object key) throws SureonException;

}
